package vistas;
import java.awt.event.ActionEvent;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTable;

import javax.swing.WindowConstants;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import clases.Estudiante;
import clases.Seccion;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Listados extends javax.swing.JFrame {
	private JLabel lblTitulo;
	private JButton jButton1;
	private AbstractAction abstractAction1;
	private JTable tblListado;
	private DefaultTableModel modelo;    
	private Vector<String> filasIdentificadoras;
	private Vector filas;
	
	

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Listados inst = new Listados();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public Listados() {
		super();
		initGUI();
		filasIdentificadoras = new Vector<String>();
		filasIdentificadoras.add("Cedula");
		filasIdentificadoras.add("Nombre");
		filasIdentificadoras.add("Apellido");
		modelo = new DefaultTableModel();
		tblListado.setModel(modelo);
		modelo.setColumnIdentifiers(filasIdentificadoras);

	}
	
	public void mostrarListado(Vector<Estudiante> vector,String titulo,boolean nota) {
		lblTitulo.setText(titulo);
		filasIdentificadoras.add("Cedula");
		filasIdentificadoras.add("Nombre");
		filasIdentificadoras.add("Apellido");
		if(nota)
			filasIdentificadoras.add("Nota Final");
		System.out.println(filasIdentificadoras.size());
		((DefaultTableModel) modelo).setColumnIdentifiers(filasIdentificadoras);
		for (Estudiante e : vector){
			filas = new Vector();
			filas.add(e.getCedula());
			filas.add(e.getNombre());
			filas.add(e.getApellido());
			if(nota)
				filas.add(e.getNota_Final());
			modelo.addRow(filas);
		}
	}
	
	private void initGUI() {
		try {
			{
				this.setSize(449, 276);
			}
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				lblTitulo = new JLabel();
				getContentPane().add(lblTitulo);
				getContentPane().add(getJTable1());
				lblTitulo.setText("Titulo del Listado");
				lblTitulo.setBounds(105, 23, 357, 15);
			}
	
		
			pack();
			this.setSize(492, 442);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private AbstractAction getAbstractAction1() {
		if(abstractAction1 == null) {
			abstractAction1 = new AbstractAction("Salir", null) {
				public void actionPerformed(ActionEvent evt) {
				}
			};
		}
		return abstractAction1;
	}
	
	private JTable getJTable1() {
		if(tblListado == null) {
			TableModel jTable1Model = 
				new DefaultTableModel();
			tblListado = new JTable();
			tblListado.setModel(jTable1Model);
			tblListado.setBounds(12, 55, 458, 184);
		}
		return tblListado;
	}

}
